<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'
import { queryRigth5 } from '@/api/business/largeScreen'

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '270px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart('03')
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart(zhlb) {
      this.chart = echarts.init(this.$el, 'macarons')

      queryRigth5({ zhlb: zhlb }).then(res => {
        console.log('queryRigth5:{}', res)
        this.chart.setOption({
          title: [
            { text: '居家各节点汇总', textStyle: { color: '#fff', fontSize: '14' }}
          ],
          tooltip: {
            trigger: 'axis',
            axisPointer: { type: 'shadow' }
          },
          grid: {
            top: '17%',
            left: '2%',
            right: '2%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              type: 'category',
              data: res.timeArray,
              axisLabel: {
                color: '#fff',
                fontSize: 12,
                fontWeight: 'bold',
                textShadowColor: '#000',
                textShadowOffsetY: 2
              }
            }
          ],
          yAxis: [
            {
              type: 'value',
              axisLine: {
                show: true,
                lineStyle: {
                  width: 2,
                  color: 'rgba(255,255,255,.6)'
                }
              },
              axisLabel: {
                color: '#fff',
                fontSize: 12,
                textShadowColor: '#000',
                textShadowOffsetY: 2
              }
            }
          ],
          series: [
            {
              name: '申请人数',
              type: 'bar',
              color: '#86c9f4',
              data: res.sqrsArray
            },
            {
              name: '评估人数',
              type: 'bar',
              color: '#4da8ec',
              data: res.pgrsArray
            },
            {
              name: '复核人数',
              type: 'bar',
              color: '#3a91d2',
              data: res.fhrsArray
            },
            {
              name: '签约人数',
              type: 'bar',
              color: '#005fa6',
              data: res.qyrsArray
            },
            {
              name: '服务人数',
              type: 'bar',
              color: '#315f97',
              data: res.fwrsArray
            }
          ]
        })
      })
    }
  }
}
</script>
